/***********************************************************************
** The Scientific Workflow Application based on Actor Petri net Model.
** It contains all elements and links, and it is the main object to 
** manage all elements and links lifecycle except for adding items
** in an application, such as creating elements from view and links
** from scene.
************************************************************************/
#ifndef APNMAPP_H
#define APNMAPP_H

#include <QtCore/QObject>
#include <QtCore/QList>
#include <QtXml/QDomDocument>
#include <QtXml/QXmlStreamWriter>
#include "../Token.h"
class APnMScene;
class Link;
class QGraphicsItem;
class GElement;

class APnMApp : public QObject
{
	Q_OBJECT

public:
	APnMApp(QObject *parent = 0);
	~APnMApp();

	void setScene(APnMScene* aScene);
	APnMScene* scene() const;

	void deleteItems(QList<QGraphicsItem*> items);

	bool addElement(GElement* newElement);
	bool deleteElement(GElement* aElement);
	void addLink(Link* newLink);
	void deleteLink(Link* aLink);

	void loadFromXml(const QDomDocument& impDoc, const QDomDocument& layDoc);
	void saveToXml(QXmlStreamWriter& impWriter, QXmlStreamWriter& layWriter);

	void selectAll();
	void updateAllLinks();

private:
	void loadImp(const QDomDocument& impDoc);
	void loadLay(const QDomDocument& layDoc);
	void saveImp(QXmlStreamWriter& impWriter);
	void saveLay(QXmlStreamWriter& layWriter);

	//process tokens
	void loadData(QDomElement& tokenElement, GElement* ele);
	void saveData(QXmlStreamWriter& dataWriter, const GElement* ele);

	GElement* findElement(const QString& name) const;

	APnMScene* mScene;

	QList<GElement*> mElements;
	QList<Link*> mLinks;	
};

#endif // APNMAPP_H
